package com.dearbinge.data.service.impl.user;

import com.dearbinge.data.api.user.UserAuthenticationManageService;
import com.dearbinge.data.dao.UserAuthenticationManage.UserAuthenticationManageMapper;
import com.dearbinge.data.pojo.user.UserAuthenticationManage;
import com.dearbinge.utils.CombineBeans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


@Service(value = "UserAuthenticationManageService")
public class UserAuthenticationManageServiceImpl implements UserAuthenticationManageService {

	@Autowired
	private UserAuthenticationManageMapper userAuthenticationManageMapper;



	@Override
	public Integer insert(UserAuthenticationManage userAuthenticationManage) {
		UserAuthenticationManage userAuthenticationManageByUserId = userAuthenticationManageMapper.getUserAuthenticationManageByUserId(userAuthenticationManage.getUserId());
		if(!StringUtils.isEmpty(userAuthenticationManageByUserId)){
			UserAuthenticationManage combineSydwCore = (UserAuthenticationManage) CombineBeans.combineSydwCore(userAuthenticationManage,userAuthenticationManageByUserId);
			if(!StringUtils.isEmpty(userAuthenticationManageMapper.getUserAuthenticationManageByUserId(userAuthenticationManage.getUserId()))){
				return userAuthenticationManageMapper.update(combineSydwCore);
			}
			if(!StringUtils.isEmpty(userAuthenticationManageMapper.getUserAuthenticationManageByShopId(userAuthenticationManage.getShpoManageId()))){
				return userAuthenticationManageMapper.update(combineSydwCore);
			}
		}
		return userAuthenticationManageMapper.insert(userAuthenticationManage);
	}


	@Override
	public Integer update(UserAuthenticationManage userAuthenticationManage) {
		return userAuthenticationManageMapper.update(userAuthenticationManage);
	}


	@Override
	public UserAuthenticationManage getUserAuthenticationManageByUserId(Integer suerID) {
		return userAuthenticationManageMapper.getUserAuthenticationManageByUserId(suerID);
	}


	@Override
	public UserAuthenticationManage getUserAuthenticationManageByShopId(Integer shopId) {
		return userAuthenticationManageMapper.getUserAuthenticationManageByShopId(shopId);
	}


}
